//
//  MYGSurgicalHistoryTableViewCell.swift
//  MYDoctor
//
//  Created by 王振明 on 2024/4/23.
//

import UIKit

class MYGSurgicalHistoryTableViewCell: UITableViewCell {
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func initUI(){
        contentView.addSubview(layerView)
        layerView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(SCALEWIDTH(15))
            make.top.equalToSuperview().offset(SCALEWIDTH(7.5))
            make.right.equalToSuperview().offset(-SCALEWIDTH(15))
            make.bottom.equalToSuperview().offset(-SCALEWIDTH(7.5))
        }

        layerView.addSubview(backView)
        backView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        backView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(10)
            make.height.equalTo(22.5)
        }
        backView.addSubview(sexView)
        sexView.snp.makeConstraints { make in
            make.left.equalTo(nameLabel.snp.right).offset(5.5)
            make.centerY.equalTo(nameLabel)
            make.height.equalTo(16)
        }
        sexView.addSubview(sexImage)
        sexImage.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(4)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 11, height: 11))
        }
        sexView.addSubview(sexLabel)
        sexLabel.snp.makeConstraints { make in
            make.left.equalTo(sexImage.snp.right).offset(4)
            make.centerY.equalToSuperview()
            make.height.equalTo(12)
            make.right.equalToSuperview().offset(-4)
        }
        backView.addSubview(moreImage)
        moreImage.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-15)
            make.centerY.equalTo(nameLabel)
            make.size.equalTo(CGSize(width: 5, height: 7.5))
        }
        backView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { make in
            make.right.equalTo(moreImage.snp.left).offset(-15)
            make.centerY.equalTo(nameLabel)
            make.height.equalTo(12)
        }
        backView.addSubview(contentLab)
        contentLab.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.top.equalTo(nameLabel.snp.bottom).offset(7.5)
            make.height.equalTo(33)
            make.bottom.equalToSuperview().offset(-12)
        }
    }
    private lazy var layerView: UIView = {
        let cont = UIView()
        cont.backgroundColor = .white
        cont.layer.shadowColor = RGBA(r: 200, g: 200, b: 200, a: 0.5).cgColor
        cont.layer.shadowOffset = CGSize(width: 2, height: 2)
        cont.layer.shadowRadius = 4.5
        cont.layer.shadowOpacity = 1
        cont.layer.cornerRadius = 10
        return cont
    }()
    
    private lazy var backView: UIView = {
        let cont = UIView()
        cont.layer.masksToBounds = true
        cont.layer.cornerRadius = 10
        return cont
    }()
    lazy var nameLabel: UILabel = {
        let cont = UILabel()
        cont.text = ""
        cont.font = .medium(16)
        cont.textColor = .rgba(70, 70, 70)
        return cont
    }()
    private lazy var contentLab: UILabel = {
        let cont = UILabel()
        cont.text = ""
        cont.font = .regular(12)
        cont.textColor = .rgba(152, 152, 152)
        cont.numberOfLines = 2
        return cont
    }()
    private lazy var timeLabel: UILabel = {
        let cont = UILabel()
        cont.text = "2023-01-01"
        cont.font = .regular(10.5)
        cont.textColor = .rgba(152, 152, 152)
        return cont
    }()
    private lazy var sexView: UIView = {
        let cont = UIView()
        cont.layer.masksToBounds = true
        cont.layer.cornerRadius = 4
        cont.backgroundColor = .rgba(105, 133, 227)
        return cont
    }()
    private lazy var sexImage: UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "common_male")
        return cont
    }()
    private lazy var sexLabel: UILabel = {
        let cont = UILabel()
        cont.text = "12岁"
        cont.font = .regular(11)
        cont.textColor = .rgba(255, 255, 255)
        return cont
    }()
    private lazy var moreImage: UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "MYG_home_moreJ")
        return cont
    }()
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
    }

    
    var model: MYGOperationListModel = MYGOperationListModel() {
        didSet {
            self.nameLabel.text = model.patient_name
            self.contentLab.text = model.name
            self.timeLabel.text = model.created_at
            self.sexLabel.text = "\(model.patient.birthday.getAge())"
            if model.patient.gender == 0 {
                self.sexImage.image = UIImage(named: "common_male")
            }else {
                self.sexImage.image = UIImage(named: "common_female")
            }
        }
    }
    
    
}
